package com.dkakunsi.monev.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="REALISASI")
public class Realisasi implements MonevEntity {
	private int id;
	private Kegiatan kegiatan;
	private int bulan;
	private long dana;
	private double fisik;
	
	public Realisasi() { }

	public Realisasi(Kegiatan kegiatan) {
		setKegiatan(kegiatan);
	}
	
	public Realisasi(Kegiatan kegiatan, int bulan) {
		setKegiatan(kegiatan);
		setBulan(bulan);
	}
	
	@Id @GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="id", length=11, nullable=false)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="kegiatan", nullable=false)
	public Kegiatan getKegiatan() {
		return kegiatan;
	}

	public void setKegiatan(Kegiatan kegiatan) {
		this.kegiatan = kegiatan;
	}

	@Column(name="bulan", length=11, nullable=false)
	public int getBulan() {
		return bulan;
	}

	public void setBulan(int bulan) {
		this.bulan = bulan;
	}

	
	@Column(name="dana", nullable=true)
	public long getDana() {
		return dana;
	}

	public void setDana(long dana) {
		this.dana = dana;
	}

	@Column(name="fisik", nullable=true)
	public double getFisik() {
		return fisik;
	}

	public void setFisik(double fisik) {
		this.fisik = fisik;
	}
	
	public double presentaseDana() {
		return (dana / kegiatan.getAnggaran()) * 100;
	}
	
	public double presentaseFisik() {
		return getFisik();
	}

}
